package com.soulless.demo.dynamicproxy.jdkproxy;

import sun.misc.ProxyGenerator;

import java.io.FileOutputStream;

/**
 * @author zenglei
 * @Description 功能描述
 * @date 2022/11/22 11:25
 */
public class DemoTest {

    public static void main(String[] args) {
        JdkMeipo jdkMeipo = new JdkMeipo();
        IPerson zhangsan = jdkMeipo.getInstance(new Zhangsan());
        /**
         * 将动态生成的代理类输出到磁盘
         */
        byte[] bytes = ProxyGenerator.generateProxyClass("$Proxy0", new Class[]{IPerson.class});
        try {
            FileOutputStream os = new FileOutputStream("$Proxy0.class");
            os.write(bytes);
            os.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

//        zhangsan.findLove();
//        zhangsan.buyInsure();
//
//        System.out.println("-----------------------");
//        IPerson zhaoliu = jdkMeipo.getInstance(new ZhaoLiu());
//        zhaoliu.findLove();
//        zhaoliu.buyInsure();
    }

}
